package com.module.app.utils;

import android.graphics.Color;
import android.text.Spannable;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * # 处理  类似微信用#来引用话题
 */
public class JingContentUtils {

    /**
     * 将含有#  进行标记颜色
     */
    public static void getJingContent(Spannable text) {
        if (text == null) {
            return;
        }
        //查找 含有  #xxxx
        String regexEmotion = "[＃|#]\\S+";
        Pattern patternEmotion = Pattern.compile(regexEmotion);
        Matcher matcherEmotion = patternEmotion.matcher(text);

        while (matcherEmotion.find()) {
            // 获取匹配到的具体字符
            String key = matcherEmotion.group();

            // 匹配字符串的开始位置
            int start = matcherEmotion.start();
            text.setSpan(new ForegroundColorSpan(Color.parseColor("#2D7CBC")), start, start + key.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        }
    }
}
